package cn.fy.sharedpreferences;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import cn.fy.sharedpreferences.activity.AppActivity;
import cn.fy.sharedpreferences.activity.GuideActivity;
import cn.fy.sharedpreferences.activity.LoginActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SharedPreferences appSharedPreferences = getSharedPreferences("APP_DATA", MODE_PRIVATE);
        //sp.edit().putString("userName", "Tom").apply();//apply才会写入到xml配置文件里面

        if(!appSharedPreferences.getBoolean("IS_GUIDE",  false)) {
            Intent intent = new Intent(MainActivity.this, GuideActivity.class);
            startActivity(intent);
            finish();
            return;
        }

        SharedPreferences userSharedPreferences = getSharedPreferences("USER_DATA", MODE_PRIVATE);

        if(!userSharedPreferences.getBoolean("IS_LOGIN",  false)) {
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
        } else {
            Intent intent = new Intent(MainActivity.this, AppActivity.class);
            startActivity(intent);
        }
        finish();
    }
}